﻿using System;
using Croxweb.Leuphana.Models;

namespace Croxweb.Leuphana.ViewModels
{
    public class MessageViewModel : ViewModelBase
    {
        private readonly Message message;

        public MessageViewModel()
        {
            this.message = new Message();
        }

        public MessageViewModel(Message message)
        {
            this.message = message;
        }

        public int Id
        {
            get { return message.Id; }
            set
            {
                message.Id = value;
                NotifyPropertyChanged("Id");
            }
        }

        public int LectureId
        {
            get { return message.LectureId; }
            set
            {
                message.LectureId = value;
                NotifyPropertyChanged("LectureId");
            }
        }

        public DateTime Received
        {
            get { return message.Received; }
            set
            {
                message.Received = value;
                NotifyPropertyChanged("Received");
            }
        }

        public String ReceivedDate
        {
            get
            {
                if (Received > DateTime.Today)
                {
                    return Received.ToShortTimeString();
                }
                if (Received > DateTime.Today.AddDays(-7))
                {
                    return Received.ToString("ddd");
                }

                return Received.ToString("dd.MM.");
            }
        }

        public String ReceivedDateTime { get { return Received.ToLongDateString() + ", " + Received.ToShortTimeString(); } }

        public Person Sender
        {
            get { return message.Sender; }
            set
            {
                message.Sender = value;
                NotifyPropertyChanged("Sender");
            }
        }

        public String Source
        {
            get { return message.Source; }
            set
            {
                message.Source = value;
                NotifyPropertyChanged("Source");
            }
        }

        public String Subject
        {
            get { return message.Subject; }
            set
            {
                message.Subject = value;
                NotifyPropertyChanged("Subject");
            }
        }

        public String Body
        {
            get { return message.Body; }
            set
            {
                message.Body = value;
                NotifyPropertyChanged("Body");
            }
        }

        public String ShortBody
        {
            get
            {
                if (message.Body.Length > 100)
                {
                    return message.Body.Substring(0, 100).Replace("\n", "").Replace("\r", " ");
                }
                else
                {
                    return message.Body.Replace("\n", "").Replace("\r", " ");
                }
            }
        }
    }
}
